package psn.zjk.netty.client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author zhangjk
 * @CREATE_TIME 2020/11/30 16:16
 */
public class TimeDecoder2 extends ReplayingDecoder<Void> {
    @Override
    protected void decode(
            ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        //ByteBuf做了处理，封装成ReplayingDecoderByteBuf，读取的字节不够时，抛出异常，继续读取
        //https://netty.io/4.1/api/io/netty/handler/codec/ReplayingDecoder.html
        out.add(in.readBytes(4));
    }

    @Override
    protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        super.decodeLast(ctx, in, out);
    }
}